<?php
session_start();
require_once("../config/include_tokyo.inc.php");

//访问权限验证
$userRole = $_SESSION['user_role'];
if($userRole == 1 || $userRole == 8){
	//管理员+团队成员
}else{
	if($userRole > 0){
		$url = "../index.php?loginError=2";//没权限
	}else{
		$url = "../index.php?loginError=3";//没登录
	}	
	echo "<script language='javascript' type='text/javascript'>";
	echo "window.location.href='$url'";
	echo "</script>";
}


//获取form值
$doFlag = $_POST["doFlag"];
$currentType = $_POST["currentType"];
$transID = $_POST["transID"];
if($doFlag == "doDelete"){
	$sqlDel = "delete from translate where id= $transID";
	$db->Execute($sqlDel);
}else if($doFlag == "toList"){
	//return list
}


//显示列表
if ($currentType == ""){
	$currentType = 1; //默认显示邮件内容的翻译列表
}
$sql = "select * from translate where type = $currentType order by order_id asc";
$result = $db->Execute($sql);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!--Begin:head-->
<? $pageTitle = "翻译管理"; ?>
<?php include("../head.php"); ?>
<!--End:head-->


<body>
<?php include("../topMenu.php"); ?>


<form name="listForm" action="../trans/transList.php" method="post">
<div id="container" >	

<div class="grayTable">	
<caption>翻译列表:
<a href="javascript:toList(1)">邮件内容</a>
<a href="javascript:toList(2)">短文内容</a>
<a href="javascript:toList(3)">长段内容</a>
<a href="QAs.php">常见问题QAs</a>
&nbsp; <input type="button" value="新增翻译" onclick="addTrans()">
</caption><br>


<table >
<thead>
	<tr>
		<th scope="col" width=70>排序编号</th>
	    <th scope="col" >中文内容</th>
		<th scope="col" >英文内容</th>
		<th scope="col" >日文内容</th>
		<th scope="col" width=95>操作</th>
	</tr>
</thead>
<tbody>
<?php
if(empty($result) || $result->RecordCount() < 1){
	echo "<tr><td colspan=5 align='center'>记录为空.</td></tr>";
}else{
	while (!$result->EOF) {
		$tempId = $result->fields['id'];
		$strTR = "<tr >";
		$strTR = $strTR."<td>".$result->fields['order_id']."</td>";
		$strTR = $strTR."<td ><textarea cols='30'  rows='4'>".$result->fields['chinese_content']."</textarea> </td>";		
		$strTR = $strTR."<td ><textarea cols='30' rows='4'>".$result->fields['english_content']."</textarea> </td>";
		$strTR = $strTR."<td ><textarea cols='30' rows='4'>".$result->fields['japanese_content']."</textarea> </td>";
		$strTR = $strTR."<td><input type='button' value='编辑' onclick='doEdit(".$result->fields['id'].")'><input type='button' value='删除' onclick='doDelete(".$result->fields['id'].")'></td>";
		$strTR = $strTR."</tr>";
		echo $strTR;
		echo "<input type='hidden' id='$tempId"."_chinese' value='".$result->fields['chinese_content']."' >";
		echo "<input type='hidden' id='$tempId"."_english' value='".$result->fields['english_content']."' >";
		echo "<input type='hidden' id='$tempId"."_japanese' value='".$result->fields['english_content']."' >";
		$result->MoveNext();	
	}
}

?>
</tbody>					
</table>	
</div>
</div><!--end container -->
<input type="hidden" name="doFlag" id="doFlag" >
<input type="hidden" name="transID" id="transID" >
<input type="hidden" name="currentType" id="currentType" >
</form>

<form name="inputForm" action="transInput.php" method="post">
<input type="hidden" name="id" id="id" >
<input type="hidden" name="action" id="action" >
</form>
<br><br><br><br>
</body>




</html>

<script>


function toList(currentType){
	document.getElementById('doFlag').value = "toList";
	document.getElementById('currentType').value = currentType;
	document.listForm.submit();
}


function  addTrans(){
	document.getElementById('action').value = "add";
	document.inputForm.submit();
}	


function doDelete(id){
	if(confirm("是否删除这条翻译记录,删除后不可恢复,是否继续?")){ 
		document.getElementById('doFlag').value = "doDelete";
		document.getElementById('transID').value = id;
		document.listForm.submit();
	}else{
		return;
	}
}


function doEdit(id){
	document.getElementById('action').value = "edit";
	document.getElementById('id').value = id;
	document.inputForm.submit();
}


function doCopyChinese(id){
	var str = document.getElementById(id+"_chinese").value;
	copy(str);
}

function doCopyEnglish(id){
	var str = document.getElementById(id+"_english").value;
	alert(str);
}

function doCopyJapanese(id){
	var str = document.getElementById(id+"_japanese").value;
	alert(str);
}



</script>

